From 946f9a1879dba4845c40db69f71779a027e1a876 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Tue, 15 Nov 2005 15:54:51 +0100 Subject: [PATCH] Added link_exists function, for neatness. Check for the existence of the pdev before issuing the diagnostic about the missing vdev. Having a pdev but no vdev is a strong indicator that the network-bridge script has run once already, and so there is nothing to worry about. Having the vdev and no corresponding pdev is still diagnosed. Signed-off-by: Ewan Mellor --- tools/examples/network-bridge | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/tools/examples/network-bridge b/tools/examples/network-bridge index 9c03a44805..2534b928c4 100755 --- a/tools/examples/network-bridge +++ b/tools/examples/network-bridge @@ -138,6 +138,23 @@ transfer_routes () { }" | sh -e } + +## +# link_exists interface +# +# Returns 0 if the interface named exists (whether up or down), 1 otherwise. +# +link_exists() +{ + if ip link show "$1" >&/dev/null + then + return 0 + else + return 1 + fi +} + + # Usage: create_bridge bridge create_bridge () { local bridge=$1 @@ -193,8 +210,12 @@ op_start () { return fi - if ! ip link show 2>/dev/null | grep -q "^[0-9]*: ${vdev}"; then - echo " + if ! link_exists "$vdev"; then + if link_exists "$pdev"; then + # The device is already up. + return + else + echo " Link $vdev is missing. This may be because you have reached the limit of the number of interfaces that the loopback driver supports. If the loopback driver is a module, you @@ -202,12 +223,13 @@ may raise this limit by passing it as a parameter (nloopbacks=); if the driver is compiled statically into the kernel, then you may set the parameter using loopback.nloopbacks= on the domain 0 kernel command line. " >&2 - exit 1 + exit 1 + fi fi create_bridge ${bridge} - if ip link show ${vdev} 2>/dev/null >/dev/null; then + if link_exists "$vdev"; then mac=`ip link show ${netdev} | grep 'link\/ether' | sed -e 's/.*ether \(..:..:..:..:..:..\).*/\1/'` preiftransfer ${netdev} transfer_addrs ${netdev} ${vdev} @@ -260,11 +282,11 @@ op_stop () { if [ "${bridge}" == "null" ]; then return fi - if ! ip link show ${bridge} >/dev/null 2>&1; then + if ! link_exists "$bridge"; then return fi - if ip link show ${pdev} 2>/dev/null >/dev/null; then + if link_exists "$pdev"; then ip link set dev ${vif0} down mac=`ip link show ${netdev} | grep 'link\/ether' | sed -e 's/.*ether \(..:..:..:..:..:..\).*/\1/'` transfer_addrs ${netdev} ${pdev} -- 2.30.2